home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbline.c,v < prev    next >
Encoding:
Text File  |  1991-02-20  |  22.3 KB  |  1,025 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     91.02.19.21.52.34;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.02.14.19.58.14;  author tve;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Original X11R4 distribution
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @Patch #1 from MIT.
  28. @
  29. text
  30. @/***********************************************************
  31. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  32. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  33.  
  34.                         All Rights Reserved
  35.  
  36. Permission to use, copy, modify, and distribute this software and its 
  37. documentation for any purpose and without fee is hereby granted, 
  38. provided that the above copyright notice appear in all copies and that
  39. both that copyright notice and this permission notice appear in 
  40. supporting documentation, and that the names of Digital or MIT not be
  41. used in advertising or publicity pertaining to distribution of the
  42. software without specific, written prior permission.  
  43.  
  44. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  45. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  46. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  47. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  48. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  49. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  50. SOFTWARE.
  51.  
  52. ******************************************************************/
  53. /* $XConsortium: mfbline.c,v 5.10 90/01/23 15:14:37 keith Exp $ */
  54. #include "X.h"
  55.  
  56. #include "gcstruct.h"
  57. #include "windowstr.h"
  58. #include "pixmapstr.h"
  59. #include "regionstr.h"
  60. #include "scrnintstr.h"
  61. #include "mistruct.h"
  62.  
  63. #include "mfb.h"
  64. #include "maskbits.h"
  65.  
  66. /* single-pixel lines on a color frame buffer
  67.  
  68.    NON-SLOPED LINES
  69.    horizontal lines are always drawn left to right; we have to
  70. move the endpoints right by one after they're swapped.
  71.    horizontal lines will be confined to a single band of a
  72. region.  the code finds that band (giving up if the lower
  73. bound of the band is above the line we're drawing); then it
  74. finds the first box in that band that contains part of the
  75. line.  we clip the line to subsequent boxes in that band.
  76.    vertical lines are always drawn top to bottom (y-increasing.)
  77. this requires adding one to the y-coordinate of each endpoint
  78. after swapping.
  79.  
  80.    SLOPED LINES
  81.    when clipping a sloped line, we bring the second point inside
  82. the clipping box, rather than one beyond it, and then add 1 to
  83. the length of the line before drawing it.  this lets us use
  84. the same box for finding the outcodes for both endpoints.  since
  85. the equation for clipping the second endpoint to an edge gives us
  86. 1 beyond the edge, we then have to move the point towards the
  87. first point by one step on the major axis.
  88.    eventually, there will be a diagram here to explain what's going
  89. on.  the method uses Cohen-Sutherland outcodes to determine
  90. outsideness, and a method similar to Pike's layers for doing the
  91. actual clipping.
  92.  
  93. */
  94.  
  95. #define OUTCODES(result, x, y, pbox) \
  96.     if (x < pbox->x1) \
  97.     result |= OUT_LEFT; \
  98.     else if (x >= pbox->x2) \
  99.     result |= OUT_RIGHT; \
  100.     if (y < pbox->y1) \
  101.     result |= OUT_ABOVE; \
  102.     else if (y >= pbox->y2) \
  103.     result |= OUT_BELOW;
  104.  
  105. #define round(dividend, divisor) \
  106. ( (((dividend)<<1) + (divisor)) / ((divisor)<<1) )
  107. #define ceiling(m,n)  (((m)-1)/(n) + 1)
  108.  
  109. /*
  110. #define SignTimes(sign, n) ((sign) * ((int)(n)))
  111. */
  112.  
  113. #define SignTimes(sign, n) \
  114.     ( ((sign)<0) ? -(n) : (n) )
  115.  
  116. #define SWAPINT(i, j) \
  117. {  register int _t = i; \
  118.    i = j; \
  119.    j = _t; \
  120. }
  121.  
  122. #define SWAPPT(i, j) \
  123. {  DDXPointRec _t; \
  124.    _t = i; \
  125.    i = j; \
  126.    j = _t; \
  127. }
  128.    
  129.  
  130. void
  131. #ifdef POLYSEGMENT
  132. mfbSegmentSS (pDrawable, pGC, nseg, pSeg)
  133.     DrawablePtr    pDrawable;
  134.     GCPtr    pGC;
  135.     int        nseg;
  136.     register xSegment    *pSeg;
  137. #else
  138. mfbLineSS (pDrawable, pGC, mode, npt, pptInit)
  139.     DrawablePtr pDrawable;
  140.     GCPtr    pGC;
  141.     int        mode;        /* Origin or Previous */
  142.     int        npt;        /* number of points */
  143.     DDXPointPtr pptInit;
  144. #endif
  145. {
  146.     int nboxInit;
  147.     register int nbox;
  148.     BoxPtr pboxInit;
  149.     register BoxPtr pbox;
  150. #ifndef POLYSEGMENT
  151.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  152. #endif
  153.  
  154.     unsigned int oc1;        /* outcode of point 1 */
  155.     unsigned int oc2;        /* outcode of point 2 */
  156.  
  157.     int *addrl;        /* address of destination pixmap */
  158.     int nlwidth;        /* width in longwords of destination pixmap */
  159.     int xorg, yorg;        /* origin of window */
  160.  
  161.     int adx;        /* abs values of dx and dy */
  162.     int ady;
  163.     int signdx;        /* sign of dx and dy */
  164.     int signdy;
  165.     int e, e1, e2;        /* bresenham error and increments */
  166.     int len;            /* length of segment */
  167.     int axis;            /* major axis */
  168.  
  169.                 /* a bunch of temporaries */
  170.     register int y1, y2;
  171.     register int x1, x2;
  172.     RegionPtr cclip;
  173.     int            alu;
  174.  
  175.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  176.     alu = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
  177.     pboxInit = REGION_RECTS(cclip);
  178.     nboxInit = REGION_NUM_RECTS(cclip);
  179.  
  180.     if (pDrawable->type == DRAWABLE_WINDOW)
  181.     {
  182.     addrl = (int *)
  183.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  184.     nlwidth = (int)
  185.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  186.     }
  187.     else
  188.     {
  189.     addrl = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  190.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  191.     }
  192.  
  193.     xorg = pDrawable->x;
  194.     yorg = pDrawable->y;
  195. #ifdef POLYSEGMENT
  196.     while (nseg--)
  197. #else
  198.     ppt = pptInit;
  199.     x2 = ppt->x + xorg;
  200.     y2 = ppt->y + yorg;
  201.     while(--npt)
  202. #endif
  203.     {
  204.     nbox = nboxInit;
  205.     pbox = pboxInit;
  206.  
  207. #ifdef POLYSEGMENT
  208.     x1 = pSeg->x1 + xorg;
  209.     y1 = pSeg->y1 + yorg;
  210.     x2 = pSeg->x2 + xorg;
  211.     y2 = pSeg->y2 + yorg;
  212.     pSeg++;
  213. #else
  214.     x1 = x2;
  215.     y1 = y2;
  216.     ++ppt;
  217.     if (mode == CoordModePrevious)
  218.     {
  219.         xorg = x1;
  220.         yorg = y1;
  221.     }
  222.     x2 = ppt->x + xorg;
  223.     y2 = ppt->y + yorg;
  224. #endif
  225.  
  226.     if (x1 == x2)
  227.     {
  228.         /* make the line go top to bottom of screen, keeping
  229.            endpoint semantics
  230.         */
  231.         if (y1 > y2)
  232.         {
  233.         register int tmp;
  234.  
  235.         tmp = y2;
  236.         y2 = y1 + 1;
  237.         y1 = tmp + 1;
  238. #ifdef POLYSEGMENT
  239.         if (pGC->capStyle != CapNotLast)
  240.             y1--;
  241. #endif
  242.         }
  243. #ifdef POLYSEGMENT
  244.         else if (pGC->capStyle != CapNotLast)
  245.         y2++;
  246. #endif
  247.         /* get to first band that might contain part of line */
  248.         while ((nbox) && (pbox->y2 <= y1))
  249.         {
  250.         pbox++;
  251.         nbox--;
  252.         }
  253.  
  254.         if (nbox)
  255.         {
  256.         /* stop when lower edge of box is beyond end of line */
  257.         while((nbox) && (y2 >= pbox->y1))
  258.         {
  259.             if ((x1 >= pbox->x1) && (x1 < pbox->x2))
  260.             {
  261.             int y1t, y2t;
  262.             /* this box has part of the line in it */
  263.             y1t = max(y1, pbox->y1);
  264.             y2t = min(y2, pbox->y2);
  265.             if (y1t != y2t)
  266.             {
  267.                 mfbVertS (alu,
  268.                       addrl, nlwidth, 
  269.                       x1, y1t, y2t-y1t);
  270.             }
  271.             }
  272.             nbox--;
  273.             pbox++;
  274.         }
  275.         }
  276. #ifndef POLYSEGMENT
  277.         y2 = ppt->y + yorg;
  278. #endif
  279.     }
  280.     else if (y1 == y2)
  281.     {
  282.         /* force line from left to right, keeping
  283.            endpoint semantics
  284.         */
  285.         if (x1 > x2)
  286.         {
  287.         register int tmp;
  288.  
  289.         tmp = x2;
  290.         x2 = x1 + 1;
  291.         x1 = tmp + 1;
  292. #ifdef POLYSEGMENT
  293.         if (pGC->capStyle != CapNotLast)
  294.             x1--;
  295. #endif
  296.         }
  297. #ifdef POLYSEGMENT
  298.         else if (pGC->capStyle != CapNotLast)
  299.         x2++;
  300. #endif
  301.  
  302.         /* find the correct band */
  303.         while( (nbox) && (pbox->y2 <= y1))
  304.         {
  305.         pbox++;
  306.         nbox--;
  307.         }
  308.  
  309.         /* try to draw the line, if we haven't gone beyond it */
  310.         if ((nbox) && (pbox->y1 <= y1))
  311.         {
  312.         int tmp;
  313.  
  314.         /* when we leave this band, we're done */
  315.         tmp = pbox->y1;
  316.         while((nbox) && (pbox->y1 == tmp))
  317.         {
  318.             int    x1t, x2t;
  319.  
  320.             if (pbox->x2 <= x1)
  321.             {
  322.             /* skip boxes until one might contain start point */
  323.             nbox--;
  324.             pbox++;
  325.             continue;
  326.             }
  327.  
  328.             /* stop if left of box is beyond right of line */
  329.             if (pbox->x1 >= x2)
  330.             {
  331.             nbox = 0;
  332.             break;
  333.             }
  334.  
  335.             x1t = max(x1, pbox->x1);
  336.             x2t = min(x2, pbox->x2);
  337.             if (x1t != x2t)
  338.             {
  339.             mfbHorzS (alu,
  340.                   addrl, nlwidth, 
  341.                   x1t, y1, x2t-x1t);
  342.             }
  343.             nbox--;
  344.             pbox++;
  345.         }
  346.         }
  347. #ifndef POLYSEGMENT
  348.         x2 = ppt->x + xorg;
  349. #endif
  350.     }
  351.     else    /* sloped line */
  352.     {
  353.         adx = x2 - x1;
  354.         ady = y2 - y1;
  355.         signdx = sign(adx);
  356.         signdy = sign(ady);
  357.         adx = abs(adx);
  358.         ady = abs(ady);
  359.  
  360.         if (adx > ady)
  361.         {
  362.         axis = X_AXIS;
  363.         e1 = ady << 1;
  364.         e2 = e1 - (adx << 1);
  365.         e = e1 - adx;
  366.  
  367.         }
  368.         else
  369.         {
  370.         axis = Y_AXIS;
  371.         e1 = adx << 1;
  372.         e2 = e1 - (ady << 1);
  373.         e = e1 - ady;
  374.         }
  375.  
  376.         /* we have bresenham parameters and two points.
  377.            all we have to do now is clip and draw.
  378.         */
  379.  
  380.         while(nbox--)
  381.         {
  382.         oc1 = 0;
  383.         oc2 = 0;
  384.         OUTCODES(oc1, x1, y1, pbox);
  385.         OUTCODES(oc2, x2, y2, pbox);
  386.         if ((oc1 | oc2) == 0)
  387.         {
  388.             if (axis == X_AXIS)
  389.             len = adx;
  390.             else
  391.             len = ady;
  392. #ifdef POLYSEGMENT
  393.             if (pGC->capStyle != CapNotLast)
  394.             len++;
  395. #endif
  396.             mfbBresS (alu,
  397.               addrl, nlwidth,
  398.               signdx, signdy, axis, x1, y1,
  399.               e, e1, e2, len);
  400.             break;
  401.         }
  402.         else if (oc1 & oc2)
  403.         {
  404.             pbox++;
  405.         }
  406.         else
  407.         {
  408.                 /*
  409.                   * let the mfb helper routine do our work;
  410.                   * better than duplicating code...
  411.                   */
  412.                 BoxRec box;
  413.                     DDXPointRec pt1Copy;    /* clipped start point */
  414.                     DDXPointRec pt2Copy;    /* clipped end point */
  415.                     int err;            /* modified bresenham error term */
  416.                     int clip1, clip2;        /* clippedness of the endpoints */
  417.                 
  418.                     int clipdx, clipdy;        /* difference between clipped and
  419.                                          unclipped start point */
  420.             DDXPointRec    pt1;
  421.                 
  422.         
  423.                 pt1.x = pt1Copy.x = x1;
  424.             pt1.y = pt1Copy.y = y1;
  425.                 pt2Copy.x = x2;
  426.             pt2Copy.y = y2;
  427.                 box.x1 = pbox->x1;
  428.                 box.y1 = pbox->y1;
  429.                 box.x2 = pbox->x2-1;
  430.                 box.y2 = pbox->y2-1;
  431.                 clip1 = 0;
  432.                 clip2 = 0;
  433.         
  434.             if (mfbClipLine (pbox, box,
  435.                      &pt1, &pt1Copy, &pt2Copy, 
  436.                      adx, ady, signdx, signdy, axis,
  437.                      &clip1, &clip2) == 1)
  438.             {
  439.                 if (axis == X_AXIS)
  440.                 len = abs(pt2Copy.x - pt1Copy.x);
  441.                 else
  442.                 len = abs(pt2Copy.y - pt1Copy.y);
  443.     
  444. #ifdef POLYSEGMENT
  445.                 if (clip2 != 0 || pGC->capStyle != CapNotLast)
  446.                 len++;
  447. #else
  448.                 len += (clip2 != 0);
  449. #endif
  450.                 if (len)
  451.                 {
  452.                 /* unwind bresenham error term to first point */
  453.                 if (clip1)
  454.                 {
  455.                     clipdx = abs(pt1Copy.x - x1);
  456.                     clipdy = abs(pt1Copy.y - y1);
  457.                     if (axis == X_AXIS)
  458.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  459.                     else
  460.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  461.                 }
  462.                 else
  463.                     err = e;
  464.                 mfbBresS   
  465.                      (alu,
  466.                       addrl, nlwidth,
  467.                       signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  468.                       err, e1, e2, len);
  469.                 }
  470.             }
  471.             pbox++;
  472.         }
  473.         } /* while (nbox--) */
  474.     } /* sloped line */
  475.     } /* while (nline--) */
  476.  
  477. #ifndef POLYSEGMENT
  478.  
  479.     /* paint the last point if the end style isn't CapNotLast.
  480.        (Assume that a projecting, butt, or round cap that is one
  481.         pixel wide is the same as the single pixel of the endpoint.)
  482.     */
  483.  
  484.     if ((pGC->capStyle != CapNotLast) &&
  485.     ((ppt->x != pptInit->x) ||
  486.      (ppt->y != pptInit->y) ||
  487.      (ppt == pptInit + 1)))
  488.     {
  489.     unsigned int _mask;
  490.     int _incr;
  491.  
  492.     if (alu == RROP_BLACK)
  493.         _mask = rmask[x2 & 0x1f];
  494.     else
  495.         _mask = mask[x2 & 0x1f];
  496.     _incr = (y2 * nlwidth) + (x2 >> 5);
  497.  
  498.     nbox = nboxInit;
  499.     pbox = pboxInit;
  500.     while (nbox--)
  501.     {
  502.         if ((x2 >= pbox->x1) &&
  503.         (y2 >= pbox->y1) &&
  504.         (x2 <  pbox->x2) &&
  505.         (y2 <  pbox->y2))
  506.         {
  507.         addrl += _incr;
  508.         switch(alu)
  509.         {
  510.             case RROP_BLACK:
  511.                 *addrl &= _mask;
  512.             break;
  513.             case RROP_WHITE:
  514.                 *addrl |= _mask;
  515.             break;
  516.             case RROP_INVERT:
  517.                 *addrl ^= _mask;
  518.             break;
  519.         }
  520.         break;
  521.         }
  522.         else
  523.         pbox++;
  524.     }
  525.     }
  526. #endif
  527. }
  528.  
  529. /*
  530.  * Draw dashed 1-pixel lines.
  531.  */
  532.  
  533. void
  534. #ifdef POLYSEGMENT
  535. mfbSegmentSD (pDrawable, pGC, nseg, pSeg)
  536.     DrawablePtr    pDrawable;
  537.     register GCPtr    pGC;
  538.     int        nseg;
  539.     register xSegment    *pSeg;
  540. #else
  541. mfbLineSD( pDrawable, pGC, mode, npt, pptInit)
  542.     DrawablePtr pDrawable;
  543.     register GCPtr pGC;
  544.     int mode;        /* Origin or Previous */
  545.     int npt;        /* number of points */
  546.     DDXPointPtr pptInit;
  547. #endif
  548. {
  549.     int nboxInit;
  550.     register int nbox;
  551.     BoxPtr pboxInit;
  552.     register BoxPtr pbox;
  553. #ifndef POLYSEGMENT
  554.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  555. #endif
  556.  
  557.     register unsigned int oc1;    /* outcode of point 1 */
  558.     register unsigned int oc2;    /* outcode of point 2 */
  559.  
  560.     int *addrl;        /* address of destination pixmap */
  561.     int nlwidth;        /* width in longwords of destination pixmap */
  562.     int xorg, yorg;        /* origin of window */
  563.  
  564.     int adx;        /* abs values of dx and dy */
  565.     int ady;
  566.     int signdx;        /* sign of dx and dy */
  567.     int signdy;
  568.     int e, e1, e2;        /* bresenham error and increments */
  569.     int len;            /* length of segment */
  570.     int axis;            /* major axis */
  571.     int x1, x2, y1, y2;
  572.     RegionPtr cclip;
  573.     int            fgrop, bgrop;
  574.     unsigned char   *pDash;
  575.     int            dashOffset;
  576.     int            numInDashList;
  577.     int            dashIndex;
  578.     int            isDoubleDash;
  579.     int            dashIndexTmp, dashOffsetTmp;
  580.     int            unclippedlen;
  581.  
  582.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  583.     fgrop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
  584.     pboxInit = REGION_RECTS(cclip);
  585.     nboxInit = REGION_NUM_RECTS(cclip);
  586.  
  587.     if (pDrawable->type == DRAWABLE_WINDOW)
  588.     {
  589.     addrl = (int *)
  590.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  591.     nlwidth = (int)
  592.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  593.     }
  594.     else
  595.     {
  596.     addrl = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  597.     nlwidth = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  598.     }
  599.  
  600.     /* compute initial dash values */
  601.      
  602.     pDash = (unsigned char *) pGC->dash;
  603.     numInDashList = pGC->numInDashList;
  604.     isDoubleDash = (pGC->lineStyle == LineDoubleDash);
  605.     dashIndex = 0;
  606.     dashOffset = 0;
  607.     miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
  608.         numInDashList, &dashOffset);
  609.  
  610.     if (isDoubleDash)
  611.     bgrop = mfbReduceRop(pGC->alu, pGC->bgPixel);
  612.  
  613.     xorg = pDrawable->x;
  614.     yorg = pDrawable->y;
  615. #ifdef POLYSEGMENT
  616.     while (nseg--)
  617. #else
  618.     ppt = pptInit;
  619.     x2 = ppt->x + xorg;
  620.     y2 = ppt->y + yorg;
  621.     while(--npt)
  622. #endif
  623.     {
  624.     nbox = nboxInit;
  625.     pbox = pboxInit;
  626.  
  627. #ifdef POLYSEGMENT
  628.     x1 = pSeg->x1 + xorg;
  629.     y1 = pSeg->y1 + yorg;
  630.     x2 = pSeg->x2 + xorg;
  631.     y2 = pSeg->y2 + yorg;
  632.     pSeg++;
  633. #else
  634.     x1 = x2;
  635.     y1 = y2;
  636.     ++ppt;
  637.     if (mode == CoordModePrevious)
  638.     {
  639.         xorg = x1;
  640.         yorg = y1;
  641.     }
  642.     x2 = ppt->x + xorg;
  643.     y2 = ppt->y + yorg;
  644. #endif
  645.  
  646.     adx = x2 - x1;
  647.     ady = y2 - y1;
  648.     signdx = sign(adx);
  649.     signdy = sign(ady);
  650.     adx = abs(adx);
  651.     ady = abs(ady);
  652.  
  653.     if (adx > ady)
  654.     {
  655.         axis = X_AXIS;
  656.         e1 = ady << 1;
  657.         e2 = e1 - (adx << 1);
  658.         e = e1 - adx;
  659.         unclippedlen = adx;
  660.     }
  661.     else
  662.     {
  663.         axis = Y_AXIS;
  664.         e1 = adx << 1;
  665.         e2 = e1 - (ady << 1);
  666.         e = e1 - ady;
  667.         unclippedlen = ady;
  668.     }
  669.  
  670.     /* we have bresenham parameters and two points.
  671.        all we have to do now is clip and draw.
  672.     */
  673.  
  674.     while(nbox--)
  675.     {
  676.         oc1 = 0;
  677.         oc2 = 0;
  678.         OUTCODES(oc1, x1, y1, pbox);
  679.         OUTCODES(oc2, x2, y2, pbox);
  680.         if ((oc1 | oc2) == 0)
  681.         {
  682. #ifdef POLYSEGMENT
  683.         if (pGC->capStyle != CapNotLast)
  684.             unclippedlen++;
  685.         dashIndexTmp = dashIndex;
  686.         dashOffsetTmp = dashOffset;
  687.         mfbBresD (fgrop, bgrop,
  688.               &dashIndexTmp, pDash, numInDashList,
  689.               &dashOffsetTmp, isDoubleDash,
  690.               addrl, nlwidth,
  691.               signdx, signdy, axis, x1, y1,
  692.               e, e1, e2, unclippedlen);
  693.         break;
  694. #else
  695.         mfbBresD (fgrop, bgrop,
  696.               &dashIndex, pDash, numInDashList,
  697.               &dashOffset, isDoubleDash,
  698.               addrl, nlwidth,
  699.               signdx, signdy, axis, x1, y1,
  700.               e, e1, e2, unclippedlen);
  701.         goto dontStep;
  702. #endif
  703.         }
  704.         else if (oc1 & oc2)
  705.         {
  706.         pbox++;
  707.         }
  708.         else /* have to clip */
  709.         {
  710.         /*
  711.          * let the mfb helper routine do our work;
  712.          * better than duplicating code...
  713.          */
  714.         BoxRec box;
  715.         DDXPointRec pt1Copy;    /* clipped start point */
  716.         DDXPointRec pt2Copy;    /* clipped end point */
  717.         int err;            /* modified bresenham error term */
  718.         int clip1, clip2;        /* clippedness of the endpoints */
  719.         
  720.         int clipdx, clipdy;        /* difference between clipped and
  721.                            unclipped start point */
  722.         DDXPointRec    pt1;
  723.     
  724.         pt1.x = pt1Copy.x = x1;
  725.         pt1.y = pt1Copy.y = y1;
  726.         pt2Copy.x = x2;
  727.         pt2Copy.y = y2;
  728.         box.x1 = pbox->x1;
  729.         box.y1 = pbox->y1;
  730.         box.x2 = pbox->x2-1;
  731.         box.y2 = pbox->y2-1;
  732.         clip1 = 0;
  733.         clip2 = 0;
  734.     
  735.         if (mfbClipLine (pbox, box,
  736.                        &pt1, &pt1Copy, &pt2Copy, 
  737.                        adx, ady, signdx, signdy, axis,
  738.                        &clip1, &clip2) == 1)
  739.         {
  740.     
  741.             dashIndexTmp = dashIndex;
  742.             dashOffsetTmp = dashOffset;
  743.             if (clip1)
  744.             {
  745.                 int dlen;
  746.     
  747.                 if (axis == X_AXIS)
  748.                 dlen = abs(pt1Copy.x - x1);
  749.                 else
  750.                 dlen = abs(pt1Copy.y - y1);
  751.                 miStepDash (dlen, &dashIndexTmp, pDash,
  752.                     numInDashList, &dashOffsetTmp);
  753.             }
  754.             if (axis == X_AXIS)
  755.                 len = abs(pt2Copy.x - pt1Copy.x);
  756.             else
  757.                 len = abs(pt2Copy.y - pt1Copy.y);
  758.     
  759. #ifdef POLYSEGMENT
  760.             if (clip2 != 0 || pGC->capStyle != CapNotLast)
  761.                 len++;
  762. #else
  763.             len += (clip2 != 0);
  764. #endif
  765.             if (len)
  766.             {
  767.                 /* unwind bresenham error term to first point */
  768.                 if (clip1)
  769.                 {
  770.                 clipdx = abs(pt1Copy.x - x1);
  771.                 clipdy = abs(pt1Copy.y - y1);
  772.                 if (axis == X_AXIS)
  773.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  774.                 else
  775.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  776.                 }
  777.                 else
  778.                 err = e;
  779.                 mfbBresD (fgrop, bgrop,
  780.                         &dashIndexTmp, pDash, numInDashList,
  781.                         &dashOffsetTmp, isDoubleDash,
  782.                         addrl, nlwidth,
  783.                         signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  784.                         err, e1, e2, len);
  785.             }
  786.         }
  787.         pbox++;
  788.         }
  789.     } /* while (nbox--) */
  790. #ifndef POLYSEGMENT
  791.     /*
  792.      * walk the dash list around to the next line
  793.      */
  794.     miStepDash (unclippedlen, &dashIndex, pDash,
  795.             numInDashList, &dashOffset);
  796. dontStep:    ;
  797. #endif
  798.     } /* while (nline--) */
  799.  
  800. #ifndef POLYSEGMENT
  801.     /* paint the last point if the end style isn't CapNotLast.
  802.        (Assume that a projecting, butt, or round cap that is one
  803.         pixel wide is the same as the single pixel of the endpoint.)
  804.     */
  805.  
  806.     if ((pGC->capStyle != CapNotLast) &&
  807.         ((dashIndex & 1) == 0 || isDoubleDash) &&
  808.     ((ppt->x != pptInit->x) ||
  809.      (ppt->y != pptInit->y) ||
  810.      (ppt == pptInit + 1)))
  811.     {
  812.     nbox = nboxInit;
  813.     pbox = pboxInit;
  814.     while (nbox--)
  815.     {
  816.         if ((x2 >= pbox->x1) &&
  817.         (y2 >= pbox->y1) &&
  818.         (x2 <  pbox->x2) &&
  819.         (y2 <  pbox->y2))
  820.         {
  821.         unsigned long _mask;
  822.         int rop;
  823.  
  824.         rop = fgrop;
  825.         if (dashIndex & 1)
  826.             rop = bgrop;
  827.         if (rop == RROP_BLACK)
  828.             _mask = rmask[x2 & 0x1f];
  829.         else
  830.             _mask = mask[x2 & 0x1f];
  831.         addrl += (y2 * nlwidth) + (x2 >> 5);
  832.         if (rop == RROP_BLACK)
  833.             *addrl &= _mask;
  834.         else if (rop == RROP_WHITE)
  835.             *addrl |= _mask;
  836.         else
  837.             *addrl ^= _mask;
  838.         break;
  839.         }
  840.         else
  841.         pbox++;
  842.     }
  843.     }
  844. #endif
  845. }
  846.  
  847. #ifndef POLYSEGMENT
  848. /*
  849.     the clipping code could be cleaned up some; most of its
  850. mess derives from originally being inline in the line code,
  851. then pulled out to make clipping dashes easier.
  852. */
  853.  
  854. int
  855. mfbClipLine(pbox, box,
  856.         ppt1Orig, ppt1, ppt2, 
  857.         adx, ady, signdx, signdy, axis,
  858.         pclip1, pclip2)
  859. BoxPtr pbox;            /* box to clip to */
  860. BoxRec box;            /* box to do calculations with */
  861. DDXPointPtr ppt1Orig, ppt1, ppt2;
  862. int adx, ady;
  863. int signdx, signdy;
  864. register int axis;
  865. int *pclip1, *pclip2;
  866. {
  867.     DDXPointRec pt1Orig, pt1, pt2;
  868.     register int swapped = 0;
  869.     int clipDone = 0;
  870.     register unsigned long utmp;
  871.     register int oc1, oc2;
  872.     int clip1, clip2;
  873.  
  874.     pt1Orig = *ppt1Orig;
  875.     pt1 = *ppt1;
  876.     pt2 = *ppt2;
  877.     clip1 = 0;
  878.     clip2 = 0;
  879.  
  880.     do
  881.     {
  882.         oc1 = 0;
  883.         oc2 = 0;
  884.         OUTCODES(oc1, pt1.x, pt1.y, pbox);
  885.         OUTCODES(oc2, pt2.x, pt2.y, pbox);
  886.  
  887.         if (oc1 & oc2)
  888.         clipDone = -1;
  889.         else if ((oc1 | oc2) == 0)
  890.         {
  891.         clipDone = 1;
  892.         if (swapped)
  893.         {
  894.             SWAPPT(pt1, pt2);
  895.             SWAPINT(oc1, oc2);
  896.             SWAPINT(clip1, clip2);
  897.         }
  898.         }
  899.         else /* have to clip */
  900.         {
  901.         /* only clip one point at a time */
  902.         if (!oc1)
  903.         {
  904.             SWAPPT(pt1, pt2);
  905.             SWAPINT(oc1, oc2);
  906.             SWAPINT(clip1, clip2);
  907.             swapped = !swapped;
  908.         }
  909.     
  910.         clip1 |= oc1;
  911.         if (oc1 & OUT_LEFT)
  912.         {
  913.           pt1.x = box.x1;
  914.           utmp = abs(box.x1 - pt1Orig.x);
  915.           utmp *= ady;
  916.           if(axis==X_AXIS)
  917.           {
  918.             pt1.y = pt1Orig.y + SignTimes(signdy, round(utmp, adx));
  919.           }
  920.           else
  921.           {
  922.         utmp <<= 1;
  923.         if (swapped)
  924.             utmp += ady;
  925.         else
  926.             utmp -= ady;
  927.         pt1.y = pt1Orig.y + SignTimes(signdy, ceiling(utmp, 2*adx));
  928.         if (swapped)
  929.             pt1.y -= signdy;
  930.           }
  931.         }
  932.         else if (oc1 & OUT_ABOVE)
  933.         {
  934.           pt1.y = box.y1;
  935.           utmp = abs(box.y1 - pt1Orig.y);
  936.           utmp *= adx;
  937.           if (axis == Y_AXIS)
  938.           {
  939.             pt1.x = pt1Orig.x + SignTimes(signdx, round(utmp, ady));
  940.           }
  941.           else
  942.           {
  943.         utmp <<= 1;
  944.         if (swapped)
  945.             utmp += adx;
  946.         else
  947.             utmp -= adx;
  948.         pt1.x = pt1Orig.x + SignTimes(signdx, ceiling(utmp, 2*ady));
  949.         if (swapped)
  950.             pt1.x -= signdx;
  951.           }
  952.         }
  953.         else if (oc1 & OUT_RIGHT)
  954.         {
  955.           pt1.x = box.x2;
  956.           utmp = abs(pt1Orig.x - box.x2);
  957.           utmp *= ady;
  958.           if (axis == X_AXIS)
  959.           {
  960.             pt1.y = pt1Orig.y + SignTimes(signdy, round(utmp, adx));
  961.           }
  962.           else
  963.           {
  964.         utmp <<= 1;
  965.         if (swapped)
  966.             utmp += ady;
  967.         else
  968.             utmp -= ady;
  969.         pt1.y = pt1Orig.y + SignTimes(signdy, ceiling(utmp, 2*adx));
  970.         if (swapped)
  971.             pt1.y -= signdy;
  972.           }
  973.         }
  974.         else if (oc1 & OUT_BELOW)
  975.         {
  976.           pt1.y = box.y2;
  977.           utmp = abs(pt1Orig.y - box.y2);
  978.           utmp *= adx;
  979.           if (axis == Y_AXIS)
  980.           {
  981.             pt1.x = pt1Orig.x + SignTimes(signdx, round(utmp, ady));
  982.           }
  983.           else
  984.           {
  985.         utmp <<= 1;
  986.         if (swapped)
  987.             utmp += adx;
  988.         else
  989.             utmp -= adx;
  990.         pt1.x = pt1Orig.x + SignTimes(signdx, ceiling(utmp, 2*ady));
  991.         if (swapped)
  992.             pt1.x -= signdx;
  993.           }
  994.         }
  995.         } /* else have to clip */
  996.     } while(!clipDone);
  997.     *ppt1 = pt1;
  998.     *ppt2 = pt2;
  999.     *pclip1 = clip1;
  1000.     *pclip2 = clip2;
  1001.  
  1002.     return clipDone;
  1003. }
  1004. #endif
  1005. @
  1006.  
  1007.  
  1008. 1.1
  1009. log
  1010. @Initial revision
  1011. @
  1012. text
  1013. @d24 1
  1014. a24 1
  1015. /* $XConsortium: mfbline.c,v 5.9 89/11/24 18:05:53 rws Exp $ */
  1016. d209 4
  1017. d215 1
  1018. a215 1
  1019.         if (pGC->capStyle != CapNotLast)
  1020. d263 4
  1021. d269 1
  1022. a269 1
  1023.         if (pGC->capStyle != CapNotLast)
  1024. @
  1025.